//
//  ViewController.m
//  FindClass
//
//  Created by tianlong on 2024/9/13.
//

#import "ViewController.h"
#import "FileRecursion.h"
#import "HBHotCoinChartLineView.h"
#import "HBHotCointChartModel.h"
#import "HBHotCoinChartView.h""
#import "HBMarketRadarGuide.h"
#import "ViewControllerB.h"
#import "HBKlineView.h"

@interface ViewController ()

@property (nonatomic, strong) FileRecursion *fileManager;
@property (nonatomic, strong) HBHotCoinChartView *chartView;
@property (nonatomic, strong) UIButton *btn;
@property (nonatomic, strong) UIButton *btn2;

@property (nonatomic, strong) HBKlineView *klineView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    NSMutableArray *arrM = [NSMutableArray array];
//    NSMutableArray *timeList = [NSMutableArray array];
//    for (int i = 0; i < 22; i++) {
//        HBHotCointChartItemModel *item = [[HBHotCointChartItemModel alloc] init];
//        item.price = [NSNumber numberWithInt:(arc4random()%138 + 5)];
//        item.time = [NSNumber numberWithInteger:1733204800 + i];
//        item.popupTitle = [NSString stringWithFormat:@"11-%d 20:00",i+1];
//        item.popupSubTitle = @"互动次数：$568.67k";
//        [arrM addObject:item];
//        [timeList addObject:[NSString stringWithFormat:[NSString stringWithFormat:@"99/%d",i+1]]];
//    }
//    HBHotCointChartModel *model = [HBHotCointChartModel new];
//    model.chartType = HBHotCointChartTypePrice;
//    model.list = arrM;
//    model.xAxisList = timeList.copy;
//    model.xAxisContentWidth = @29;
//    
//        self.chartView = [[HotCoinChartView alloc] initWithChartModel:model];
//        self.chartView.frame = CGRectMake(16, 200, self.view.bounds.size.width - 32, 138);
//        [self.view addSubview:self.chartView];
    
    
    // xcode 中获取当前项目所在路径
//    NSString *currentFilePath = [NSString stringWithUTF8String:__FILE__];
//    NSString *projectPath = [currentFilePath stringByDeletingLastPathComponent];
//    
//    
//    self.fileManager = [[FileRecursion alloc] init];
//    [self.fileManager startTraversingDirectory:@"/Users/tianlong/Desktop/FindClassTest/FindClass"];
//    
//    dispatch_async(dispatch_get_global_queue(0, 0), ^{
//        NSString *directoryPath = @"/Users/tianlong/Desktop/FindClassTest/FindClass";
//        NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:directoryPath];
//        NSArray *contents = enumerator.allObjects.copy;
//        //测试证明，contents中的内容与遍历的内容是一致的，所以可以通过 contents 直接遍历所有目录文件
//        NSLog(@"contents==>%@,contents.count==%ld",contents,contents.count);
//    });
    
    self.btn = [[UIButton alloc] init];
    [self.btn addTarget:self action:@selector(clickedBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btn];
    self.btn.backgroundColor = UIColor.redColor;
    self.btn.frame = CGRectMake(100, 400, 100, 50);
    
    self.btn2 = [[UIButton alloc] init];
    [self.btn2 addTarget:self action:@selector(clickedBtn2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btn2];
    self.btn2.backgroundColor = UIColor.blueColor;
    self.btn2.frame = CGRectMake(250, 400, 100, 50);
}

- (void)clickedBtn2:(UIButton *)button {
    [self.klineView removeFromSuperview];
}

- (void)clickedBtn:(UIButton *)button {
    
    if (self.klineView) {
        [self.view addSubview:self.klineView];
    } else {
        self.klineView = [[HBKlineView alloc] init];
        self.klineView.backgroundColor = UIColor.greenColor;
        [self.view addSubview:self.klineView];
    }
    self.klineView.frame = CGRectMake(10, 10, 200, 100);
    
    return;
    
//    [HBMarketRadarGuide show:nil];
    
    NSMutableArray *arrM = [NSMutableArray array];
    NSMutableArray *timeList = [NSMutableArray array];
    for (int i = 0; i < 22; i++) {
        HBHotCointChartItemModel *item = [[HBHotCointChartItemModel alloc] init];
//        item.originalValue = [NSNumber numberWithInt:(arc4random()%138 + 5)];
        item.originalValue = [NSNumber numberWithInt:(i*5 + 10)];
        if (i == 1) {
            item.originalValue = [NSNumber numberWithInt:(1000)];
        }
        item.popupDate = [NSString stringWithFormat:@"11-%d 20:00",i+1];
        item.popupContent = [NSString stringWithFormat:@"互动次数：%@",item.originalValue.stringValue];
        [arrM addObject:item];
        [timeList addObject:[NSString stringWithFormat:@"%d/%d",arc4random()%99,i+1]];
    }
    HBHotCointChartModel *model = [HBHotCointChartModel new];
    model.pointList = arrM;
    model.xList = timeList.copy;
    if (!self.chartView) {
        self.chartView = [[HBHotCoinChartView alloc] initWithChartModel:model];
        self.chartView.frame = CGRectMake(16, 200, self.view.bounds.size.width - 32, 138);
        [self.view addSubview:self.chartView];
    } else {
        [self.chartView reload:model];
    }
}

@end
